/*
 * Copyright (C) 2014 Bob Browning
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.muy.mpc.intellij.codeinsight.postfix.templates.guava.surround;

import com.intellij.codeInsight.template.Template;
import com.intellij.codeInsight.template.impl.TextExpression;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Conditions;
import com.intellij.psi.PsiElement;
import com.muy.mpc.intellij.codeinsight.postfix.internal.RichChooserStringBasedPostfixTemplate;
import com.muy.mpc.intellij.codeinsight.postfix.utils.LinePsiElementUtils;
import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Postfix template for guava {@code com.google.common.base.Splitter}.
 *
 * @author Bob Browning
 */
public class GuMapsNewLinkedHashMapPostfixTemplate extends RichChooserStringBasedPostfixTemplate {

    public GuMapsNewLinkedHashMapPostfixTemplate() {
        super("guNLinkedHashMap", "Map<String,String> maps = Maps.newLinkedHashMap();", Conditions.alwaysTrue());
    }

    @Override
    public void setVariables(@NotNull Template template, @NotNull PsiElement element) {
        List<String> variables = LinePsiElementUtils.lineVariable(element);
        for (int i = 0; i < variables.size(); i++) {
            template.addVariable(String.valueOf(i + 1), new TextExpression(variables.get(i)), true);
        }
    }

    @Override
    public final String getTemplateString(@NotNull PsiElement element) {
        return "java.util.Map<$1$,$2$> $expr$ = com.google.common.collect.Maps.newLinkedHashMap();";
    }

    @Override
    protected boolean shouldUseStaticImportIfPossible(@NotNull Project project) {
        return false;
    }

    @Override
    protected PsiElement elementForRemoving(PsiElement expr) {
        return LinePsiElementUtils.elementForRemoving(expr);
    }
}
